package plantshop.tests;
import static org.junit.Assert.*;

import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.HashMap;

import javax.swing.JFrame;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import plantshop.model.Customer;
import plantshop.model.Display;
import plantshop.model.Game;
import plantshop.model.Location;
import plantshop.model.Player;
import plantshop.view.View;
import plantshop.view.listeners.StoreMouseListener;


public class StoreMouseListenerTest {
	static Display d1,d2,d3;
	static StoreMouseListener sml;
	static View v;
	static Game g;
	static Customer c;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		g = new Game(1, 1);
		v = new View(g, new Player(),
					 new HashMap<String, BufferedImage>(), new JFrame(), false, new HashMap<String, BufferedImage[]>(), false);
		sml = new StoreMouseListener();
		
		d1 = new Display(6,0,0,true, 1, 1);
		d1.setBottomRight(new Location(50,100));
		d1.setTopLeft(new Location(25,50));
		d1.setRows(3);
		d1.setColumns(2);
		
		d2 = new Display(6,0,0,true, 1, 1);
		d2.setBottomRight(new Location(25,25));
		d2.setTopLeft(new Location(0,0));
		d2.setRows(3);
		d2.setColumns(2);
		
		d3 = new Display(6,0,0,true, 1, 1);
		d3.setBottomRight(new Location(250,150));
		d3.setTopLeft(new Location(225,100));
		d3.setRows(3);
		d3.setColumns(2);
		
		g.getStore().getFront().clear();
		g.getStore().getFront().add(d1);
		g.getStore().getFront().add(d2);
		g.getStore().getFront().add(d3);
		
		Customer.setEntrance(new Location(1000, 1000));
		Customer.setExit(new Location(1920, 1080));
		Customer.setXScale(1);
		Customer.setYScale(1);
		c = Customer.makeCustomer();
		g.getStore().addCustomer(c);
		c.setLoc(new Location(500, 500));
		System.out.println(g.getCustomers());
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testFindPlot() {
		assertEquals(d1, StoreMouseListener.findPlot(new Point(30,75)));
		assertEquals(d2, StoreMouseListener.findPlot(new Point(0, 0)));
		assertEquals(d3, StoreMouseListener.findPlot(new Point(250, 150)));
		assertEquals(null, StoreMouseListener.findPlot(new Point(1920, 1080)));
	}

	@Test
	public void testFindLocationInPlot() {
		assertEquals(0, StoreMouseListener.findLocationInPlot(new Point(25, 50)));
		assertEquals(1, StoreMouseListener.findLocationInPlot(new Point(50, 65)));
		assertEquals(2, StoreMouseListener.findLocationInPlot(new Point(25, 81)));
		assertEquals(3, StoreMouseListener.findLocationInPlot(new Point(50, 66)));
		assertEquals(4, StoreMouseListener.findLocationInPlot(new Point(36, 100)));
		assertEquals(5, StoreMouseListener.findLocationInPlot(new Point(37, 82)));
		assertEquals(5, StoreMouseListener.findLocationInPlot(new Point(50, 100)));
		assertEquals(-1, StoreMouseListener.findLocationInPlot(new Point(1920, 1080)));
	}
	
	@Test
	public void testFindCustomer()
	{
		assertEquals(c, StoreMouseListener.findCustomer(new Point(500, 500)));
		assertEquals(c, StoreMouseListener.findCustomer(new Point(625, 500)));
		assertEquals(c, StoreMouseListener.findCustomer(new Point(500, 550)));
		assertEquals(c, StoreMouseListener.findCustomer(new Point(625, 550)));
		assertEquals(null, StoreMouseListener.findCustomer(new Point(0, 0)));
	}

}
